#include <iostream>
#include <sw/redis++/redis++.h>
#include <vector>
#include <string>
#include "PPrint.hpp"
#include <chrono>

using std::cout;
using std::endl;
using std::string;
using std::unordered_map;
using std::vector;

using sw::redis::Redis;
using namespace std::chrono_literals;

void test1(Redis &redis)
{
    std::cout << "lpush and lrange" << std::endl;
    redis.flushall();

    redis.lpush("key", "111");
    redis.lpush("key", {"222", "333"});

    vector<string> values = {"555", "666", "777"};
    redis.lpush("key", values.begin(), values.end());

    vector<string> results;
    auto it = std::back_inserter(results);
    redis.lrange("key", 0, -1, it);
    // printContainer(results);

    auto result = redis.lpop("key");
    cout << result.value() << endl;
    if (result)
        cout << "lpop: " << result.value() << endl;

    result = redis.rpop("key");
    if (result)
        cout << "lpop: " << result.value() << endl;
}

void test2(Redis &redis)
{
    std::cout << "blpop and brpop" << std::endl;
    redis.flushall();

    auto result = redis.blpop({"key", "key1", "key2"}, 10);
    if (result)
    {
        cout << result.value().first << ":" << result.value().second << endl;
    }
    else
    {
        cout << "result not value!!!" << endl;
    }
}

void test3(Redis &redis)
{
    cout << "llen" << endl;
    redis.lpush("key", "111");
    redis.lpush("key", {"222", "333"});

    auto len = redis.llen("key");
    cout << "len: " << len << endl;
}

int main()
{
    Redis redis("tcp://127.0.0.1:6379");
    test3(redis);
    return 0;
}
